{% extends "ProjetUserBundle::layout.html.twig" %}

{% block title %}
	Accueil - {{ parent() }}
{% endblock %}

{% block fos_user_content %}
<script type="text/javascript">
$(document).ready(function(){

	function timer()
	{
		
		var dt=new Date();	
		
		//alert('{{ path("message_show", { "id": entity.id }) }}');
		//alert('test conversation');
	    jQuery.ajax({
		    url: '{{ path("nouvelle_conversation", { "id_message": entity.id }) }}',
		    success: function(data){
			    if(data != '')
			    {
			    	$('#conversations').append(data);
			    }
		    	
		    }
		});
	    setTimeout(timer, 2000);
	}
  	timer();

});
</script>
<div class="alert alert-danger"><h2>Objet : {{ entity.sujet }}</h2></div>

<div class="alert alert-warning"><h3>Avec  : 
		{{ entity.user == app.user ? entity.destinataire : entity.user }}
</h3></div>


<div id="conversations">
{% for c in conversations %}
	{% if c.user == app.user %}
		<div class="span4 alert alert-danger">
			<div class="btn alert-info">moi :</div> 
	{% else %}
		<div class="margin-right alert alert-success">
			<div class="btn alert-info">{{ c.user }} :</div> 
	{% endif %}
			
				<p>{{ c.msg }}</p>
				<div class="pull-right alert-info">{{ c.createdat|date('Y-m-d H:i:s') }}</div>
		</div>

{% endfor %}
</div>



<div class="span4" id="newComment">
	{% include "ProjetUserBundle:Conversation:new.html.twig" %}
</div>


{% endblock %}